package com.example.wan1.adapter;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.example.wan1.R;
import com.example.wan1.model.BannerBean;
import com.example.wan1.utils.StatusBarUtil;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/***
 * 创建时间：2020/11/25 21:37
 * 创建人：10850
 * 功能描述：
 */
public class BannerImageAdapter extends BannerAdapter<BannerBean, BannerImageAdapter.BannerViewHolder> {
    public BannerImageAdapter(List<BannerBean> datas) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(datas);
    }

    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_banner_item, parent, false);
        return new BannerViewHolder(inflate);
    }

    @Override
    public void onBindView(BannerViewHolder holder, BannerBean data, int position, int size) {
        holder.mTextView.setText(Html.fromHtml(data.getTitle()));
        Glide.with(holder.itemView.getContext()).load(data.getImagePath())
                .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC))
                .into(holder.mImageView);
    }

    public class BannerViewHolder extends RecyclerView.ViewHolder {
        private ImageView mImageView;
        private TextView mTextView;

        public BannerViewHolder(@NonNull View itemView) {
            super(itemView);
            mImageView = itemView.findViewById(R.id.home_banner_item_iv);
            mTextView = itemView.findViewById(R.id.home_banner_item_tv);
        }
    }
}